// 使用provider状态管理
import 'package:flutter/material.dart';
import 'package:flutter_study/providers/counter_provider.dart';
import 'package:provider/provider.dart';

class Page3 extends StatelessWidget {
  const Page3({super.key});

  @override
  Widget build(BuildContext context) {
    final counter = context.watch<CounterProvider>();
    // final counter = Provider.of<CounterProvider>(context); // 读取状态
    return Scaffold(
      appBar: AppBar(title: const Text('Page3')),
      body: Center(
        child: Column(
          // mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Count: ${counter.count}'), // 读取状态
            // Text('Count:${context.watch<CounterProvider>().count}'), // 读取状态
            ElevatedButton(
              onPressed: () {
                counter.increment(); // 更新状态
                // context.read<CounterProvider>().increment(); // 更新状态
              },
              child: const Text('Increment'),
            ),
          ],
        ),
      ),
    );
  }
}
